use chrono::{Datelike, NaiveDateTime, Timelike};
use std::{
    fs::{self, File},
    path::Path,
};

// fileBuffer: &[u8]
pub fn dir_exists(ts: NaiveDateTime) -> bool {
    dotenv::dotenv().ok();
    let yyyy = ts.year();
    let mm = ts.month();
    let dd = ts.day();
    let hh = ts.hour();
    let upload_path = dotenv::var("upload_path").expect("upload_path is not define");
    // let timestamp = ts.and_utc().timestamp();
    let dir_str = format!("{}/{}/{}/{}/{}", upload_path, yyyy, mm, dd, hh);
    let path = Path::new(&dir_str);

    if !path.exists() {
        fs::create_dir_all(path).unwrap();
    } else {
        println!("Directory already exists: {}", dir_str);
    }

    true
}